<html>
<body>

<a href="javascript:kangxihui_invoke('details', 100, test_callback)" >invoke test</a>
<script>
function test_callback(path, data){
	alert("invoke success!\nfrom:" + path + "\n" + data);
}

/*iOS functions: 注入三个js*/

function kangxihui_invoke(path,data,callback){
	kangxihui_regcb(callback);
	var url="http://localhost/"+path+"?"+data;
	if(callback){
		url += "&_cb_="+callback.cbidx;
	}
	window.location.href=url;
}
function kangxihui_regcb(func){
	if(!func)return;
	var self=kangxihui_callback;
	if(!self.cbs)self.cbs={cnt:0};
	self=self.cbs;
	if(!func.cbidx){
		func.cbidx="cb"+(self.cnt++);
		self[func.cbidx]=func;
	};
}


/*拦截url成功后主动调此回调*/
function kangxihui_callback(cb,path,data){
	if(!cb)return;
	var self=kangxihui_callback;
	if(!self.cbs)return;
	cb = self.cbs[cb];
	if(!cb)return;
	cb(path,data);
}


</script>

</body>
</html>